package com.mutouren.common.session;

import com.mutouren.common.session.impl.LocalSessionImpl;
import com.mutouren.common.session.impl.RemoteSessionImpl;
import com.mutouren.common.session.impl.ServletSessionImpl;
import com.mutouren.common.utils.UUIDUtils;

public class SessionManager {
	
	public static volatile Session session = null; 

	public static String createSessionId() {
		return UUIDUtils.createBase64UUID();
	}
	
	public static Session getSession() {
		if (session == null) {
			createSession();
		}
		return session;
	}
	
	private synchronized static void createSession() {
		if (session == null) {
			switch (SessionConfig.getSessionType()) {
			case Servlet:
				session = new ServletSessionImpl(); break;
			case Local:
				session = new LocalSessionImpl(); break;
			case Remote:
				session = new RemoteSessionImpl(); break;
			}
			
		}
	}
}
